package gameobjects;

import gameengine.EntityMgr;

public class PlayerEntity extends Actor {

	private Bullet bullet;
	private long lastLaunchTime;
	private int cooldown;
	private int bulletCount;
	private int maxBullet;
	private String weaponName;

	public PlayerEntity(int h) {
		super(h, "hero", "hero", 10, 410, 32, 38, 1, 8, 0);
		this.setJumpHeight(140);
		bullet = null;
		lastLaunchTime = -1;
		resetWeapon();
	}
	
	public int getCooldown() {
		return cooldown;
	}

	public void setCooldown(int cooldown) {
		this.cooldown = cooldown;
	}

	public int getBulletCount() {
		return bulletCount;
	}

	public void setBulletCount(int bulletCount) {
		this.bulletCount = bulletCount;
	}

	public int getMaxBullet() {
		return maxBullet;
	}

	public void setMaxBullet(int maxBullet) {
		this.maxBullet = maxBullet;
	}
	
	public Bullet getBullet(){
		return bullet;
	}
	
	public void setBullet(Bullet bullet){
		this.bullet = bullet;
	}
	
	public String getWeaponName() {
		return weaponName;
	}

	public void setWeaponName(String weaponName) {
		this.weaponName = weaponName;
	}
	
	public void resetWeapon(){
		Pistol hg = new Pistol(-1,-1,-1);
		bullet = hg.getBulletData();
		cooldown =  hg.getCooldown();
		bulletCount = hg.getMagSize();
		maxBullet = hg.getMagSize();
		weaponName = hg.getName();
	}

	public void fire(EntityMgr entityMgr, long tick){
		if (tick - lastLaunchTime > cooldown){
			entityMgr.createBullet(this, tick);
			if (bulletCount != -1) {
				bulletCount--;
				if (bulletCount == 0)
					resetWeapon();
			}
			lastLaunchTime = tick;
		}
	}
	
}
